<?php


namespace app\admin\controller\Feedback;


use app\admin\controller\BaseController;
use app\admin\model\Feedback\UserFeedbackModel;
use app\Utils\Util;
use think\facade\Db;
use think\Request;

class UserFeedback extends BaseController
{

    /**
     * 分页查询
     * @param Request $request
     * @return array
     */
    public function getFeedbackList(Request $request)
    {
        $param = $request->param();
        $where = [];
        $page = $param['page'];
        $limit = $param['limit'];
        $status = !empty($param['status']) ? $param['status'] : "";
        if (empty($page)) {
            $page = 1;
        }
        if (empty($limit)) {
            $limit = 10;
        }
        if (!empty($status)) {
            if ($status == 1) {
                array_push($where, ['status', '=', 1]);
            }
            if ($status == 2) {
                array_push($where, ['status', '=', 0]);
            }
        }
        $list = UserFeedbackModel::getUserFeedbackListWhere($page, $limit, $where);
        $count = UserFeedbackModel::getUserFeedbackCountWhere($where);

        return Util::returnPageJson(self::CODE_DATA, $count, $list, "");
    }

    /**
     * 更新
     * @param Request $request
     * @return array
     */
    public function editFeedbackType(Request $request)
    {
        $param = $request->param();
        $id = $param['id'];
        $status = !empty($param['status']) ? $param['status'] : "";
        if (empty($id)) {
            return Util::returnJson(self::CODE_ERROR, null, "参数错误");
        }
        if (!empty($status)) {
            if ($status == "on") {
                $save['status'] = 1;
            } else {
                $save['status'] = 0;
            }
        }else{
            $save['status'] = 0;
        }
        $flag = UserFeedbackModel::updateUserFeedbackWhere([['id', '=', $id]], $save);
        if ($flag) {
            return Util::returnJson(self::CODE_SUCCESS, null, "修改成功");
        } else {
            return Util::returnJson(self::CODE_ERROR, null, "修改失败");
        }
    }
}